package com.kmt.plaza.controller;

import com.kmt.plaza.entity.Product;
import com.kmt.plaza.entity.ProductComments;
import com.kmt.plaza.sevice.ProductDetailsService;
import com.kmt.plaza.vo.ProductCommentsVO;
import com.kmt.plaza.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/productComments")
@Api(value = "提供商品详情页信息",tags = "商品详情")
@CrossOrigin
public class ProductDetailsController {
    @Autowired
    private ProductDetailsService productDetailsService;
    /**
     * 管理员查询用户分页
     */
    @ApiOperation(value = "用户评论分页列表查询")
    @GetMapping(value = "/findAllComments/{productId}")
    public ResultVO findAllComments(@PathVariable String productId, int pageNum, int limit)
    {
        return productDetailsService.findAllComments(productId,pageNum,limit);
    }

    @ApiOperation(value = "商品参数信息查询")
    @GetMapping(value = "/getProductParams/{productId}")
    public ResultVO getProductParams(@PathVariable String productId)
    {
        return productDetailsService.getProductParams(productId);
    }
    @ApiOperation(value = "商品评论统计接口")
    @GetMapping(value = "/getProductCommentStat/{productId}")
    public ResultVO getProductCommentStat(@PathVariable String productId)
    {
        return productDetailsService.getProductCommentStat(productId);
    }
    /**
     * 用户评价
     */
    @ApiOperation(value = "用户评论接口")
    @PutMapping(value = "/addComment")
    public ResultVO addComment(ProductCommentsVO productCommentsVO)
    {
        if(productCommentsVO != null){
            productCommentsVO.setSepcName(new Date());
            productCommentsVO.setIsShow(1);
        }
        return productDetailsService.addComment(productCommentsVO);
    }

}
